package org.lq.rbac.controlller;


import org.lq.rbac.dto.MenuDTO;


import org.lq.rbac.service.MenuService;
import org.lq.rbac.vo.MenuVO;
import org.lq.rbac.vo.util.Populate;
import org.lq.rbac.web.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    MenuService menuService;

//123456123456
    @GetMapping(value = "/list")
    public HttpResult<List<MenuVO>> list(@RequestParam(name="id",defaultValue = "0") Integer super_id) throws Exception {
        List<MenuDTO> menuDTOList=menuService.list(super_id);
//        HttpResult<List<MenuDTO>> result=new HttpResult<>();
//        result.setData(menuDTOList);
//        result.setCode(1);
//        result.setMessage("数据正常");
        LinkedList<Object> menuVOList = new LinkedList<>();
        for (MenuDTO menuDTO:menuDTOList){
            MenuVO menuVO = new MenuVO();
            Populate.dto2vo(menuDTO,menuVO);
            menuVOList.add(menuVO);
        }
        return HttpResult.ok(menuDTOList,"数据正常");
    }


    @GetMapping("/allMenus")
    public HttpResult<List<MenuVO>> allMenus() throws Exception {


       List<MenuDTO> menuDTOList= menuService.allMenus();


       LinkedList<Object> menuVOList = new LinkedList<>();
        for (MenuDTO menuDTO:menuDTOList){
            MenuVO menuVO = new MenuVO();
            Populate.dto2vo(menuDTO,menuVO);
            menuVOList.add(menuVO);
        }
        return HttpResult.ok(menuDTOList,"数据正常");



    }



}
